fix: use correct POSIX signal exit convention for KeyboardInterrupt in test.py#5
Closed
Dhakshin2007 wants to merge 1 commit intofacebook:mainfrom
Closed
Conversation
Using sys.exit(signal.SIGINT) exits with code 2, which shells and CI systems interpret as a regular error, not a signal-terminated process. The POSIX convention for a process terminated by signal N is to exit with code 128 + N. For SIGINT (N=2), this is exit code 130. The correct idiomatic approach is to reset SIGINT to its default handler and re-raise it — the OS then sets the exit status automatically, allowing shells and CI runners to correctly detect that the process was interrupted rather than failing with a generic error code.
|
@brittanyrey has imported this pull request. If you are a Meta employee, you can view this in D101664858. |
|
@brittanyrey merged this pull request in 3572844. |
Contributor
|
Thank you for your contribution to Lifeguard! |
Contributor
Author
Always, Thanks for Prompt Response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
In
test.py, theKeyboardInterrupthandler does:signal.SIGINThas the integer value2. So this is equivalent tosys.exit(2)— a plain non-zero error exit. This is incorrect because:128 + Nto indicate a process was killed by signalN. For SIGINT, the expected exit code is 130 (128 + 2).2is treated as a generic error, not an interrupt.$?andset -ebehave incorrectly.Fix
Reset the SIGINT handler to the OS default and re-raise the signal. The OS then terminates the process with the correct exit status (130) automatically:
This is the idiomatic Python pattern for correct SIGINT propagation (referenced in Python docs and PEP recommendations).
Impact
This is a correctness bug that affects CI behaviour — on Ctrl+C or SIGINT from a test runner, the script exits with code
2(error) instead of130(interrupted). This can cause CI pipelines to report a test failure instead of a cancellation.